﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RecipeManager
{
    public partial class LoadProgressForm : Form
    {
        #region Count

        public int Count
        {
            get
            {
                return _pbMain.Maximum;
            }
            set
            {
                _pbMain.Maximum = value;
                _pbMain.Minimum = 0;
                UpdateProgressText();
            }
        }

        #endregion

        #region Value

        public int Value
        {
            get
            {
                return _pbMain.Value;
            }
            set
            {
                _pbMain.Value = value;
                UpdateProgressText();
                if (Value == _pbMain.Maximum)
                {
                    if (Value > 50)
                    {
                        System.Threading.Thread.Sleep(1000);
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(1000);
                        Application.DoEvents();
                    }
                    this.Close();
                }
            }
        }

        #endregion

        private void UpdateProgressText()
        {
            _lblState.Text = string.Format("{0} / {1}", Value, Count);
            Application.DoEvents();
        }

        public LoadProgressForm()
        {
            InitializeComponent();
        }

        private void LoadProgressForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = Value != _pbMain.Maximum;
        }
    }

}
